---
title: File Generation
---

**FileGenerationTools** enable an Agent or Team to generate files in multiple formats.

<Tip>
Supported file types: 
- JSON 
- CSV 
- PDF
- TXT
</Tip>

## Prerequisites

1. **Install the libraries:**
   ```bash
   pip install reportlab openai
   ```

2. **Set your credentials:**
    For OpenAI API:
    ```bash
    export OPENAI_API_KEY="your-openai-api-key"
    ```

## Example

The following agent will generate files in different formats based on user requests.

```python file_generation_tools.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.file_generation import FileGenerationTools

agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    db=SqliteDb(db_file="tmp/test.db"),
    tools=[FileGenerationTools(output_directory="tmp")],  
    description="You are a helpful assistant that can generate files in various formats.",
    instructions=[
        "When asked to create files, use the appropriate file generation tools.",
        "Always provide meaningful content and appropriate filenames.",
        "Explain what you've created and how it can be used.",
    ],
    markdown=True,
)

response =agent.run(
        "Create a PDF report about renewable energy trends in 2024. Include sections on solar, wind, and hydroelectric power."
    )
print(response.content)
    if response.files:
        for file in response.files:
            print(f"Generated file: {file.filename} ({file.size} bytes)")
            if file.url:
                print(f"File location: {file.url}")
    print()
```

<Note>
You can use the `output_directory` parameter to specify a custom output directory for the generated files. 
If not specified, the files will be available in the `RunOutput` object.
</Note>

## Toolkit Params

| Parameter                 | Type   | Default | Description                                     |
| ------------------------- | ------ | ------- | ----------------------------------------------- |
| `enable_json_generation`  | `bool` | `True`  | Enables JSON file generation                    |
| `enable_csv_generation`   | `bool` | `True`  | Enables CSV file generation                     |
| `enable_pdf_generation`   | `bool` | `True`  | Enables PDF file generation (requires reportlab)|
| `enable_txt_generation`   | `bool` | `True`  | Enables text file generation                    |
| `output_directory`        | `str`  | `None`  | Custom output directory path                    |
| `all`                     | `bool` | `False` | Enables all file generation types when True     |

## Toolkit Functions

| Name                  | Description                                                    |
| --------------------- | -------------------------------------------------------------- |
| `generate_json_file`  | Generates a JSON file from data (dict, list, or JSON string)  |
| `generate_csv_file`   | Generates a CSV file from tabular data                        |
| `generate_pdf_file`   | Generates a PDF document from text content                    |
| `generate_text_file`  | Generates a plain text file from string content              |

## Developer Resources

- View [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/file_generation.py)
- View [Cookbook](https://github.com/agno-agi/agno/tree/main/cookbook/tools/file_generation_tools.py)
